package com.ty.web;

import com.ty.bean.Role;
import com.ty.service.UsersService;
import com.ty.service.impl.UsersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 田野
 */
@WebServlet(urlPatterns = "/power/user/getRoleList")
public class GetRoleServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 1、接收参数，此时无参数接收，查询所有的角色信息列表
        // 2、调用service方法
        UsersService service = new UsersServiceImpl();
        List<Role> roleList = service.getRoleList();
        // 测试一把
        System.out.println("查询所有角色信息列表：" + roleList);
        // 3、存值并跳转页面，此时不能直接跳转到add.jsp页面。而是要跳转到servlet，然后再跳转到add.jsp(转发)
        req.setAttribute("rlist", roleList);
        req.getRequestDispatcher("add.jsp").forward(req, resp);
    }
}
